﻿<template>
    <div class="container" style="width:99%;margin-top:-25px;">
        <!-- 查询条件 -->
        <div class="query-box">
            <el-form :model="queryBox" status-icon ref="queryBox">
                <el-row>
                    <el-col :span="4">
                        <div class="depart-box">
                            <div class="slect-title">客户类型</div>
                            <el-select clearable v-model="queryBox.type" filterable>
                                <el-option
                                    v-for="item in student_type_options"
                                    :key="item.lable"
                                    :label="item.value"
                                    :value="item.key"
                                ></el-option>
                            </el-select>
                        </div>
                    </el-col>
                    <!-- <el-col :span="4">
                        <crm-perms-box perms="customer:student:source">
                            <div class="depart-box">
                                <div class="slect-title">客户来源</div>
                                <el-select
                                    filterable
                                    clearable
                                    v-model="queryBox.dataFrom"
                                    placeholder="请选择"
                                >
                                    <el-option
                                        v-for="item in student_data_from_options"
                                        :key="item.key"
                                        :label="item.value"
                                        :value="item.key"
                                    >{{item.value}}</el-option>
                                </el-select>
                            </div>
                        </crm-perms-box>
                    </el-col> -->
                    <el-col :span="4">
                        <div class="depart-box">
                            <div class="slect-title">客户进展</div>
                            <el-form-item @change="student_progress_change">
                                <el-select clearable v-model="queryBox.progress" placeholder="请选择">
                                    <el-option
                                        v-for="item in student_progress_options"
                                        :key="item.value"
                                        :label="item.value"
                                        :value="item.key"
                                    >{{item.value}}</el-option>
                                </el-select>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="code">
                            <el-input v-model="queryBox.code" placeholder="客户编号">
                                <template slot="prepend">客户编号</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="name">
                            <el-input v-model="queryBox.name" placeholder="学生名称">
                                <template slot="prepend">学生名称</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="school">
                            <el-input v-model="queryBox.school" placeholder="学校名称">
                                <template slot="prepend">学校名称</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    
                    <el-col :span="4">
                        <el-form-item label prop="school">
                            <el-input v-model="queryBox.phone" placeholder="联系电话">
                                <template slot="prepend">联系电话</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <div class="depart-box">
                            <div class="slect-title">创建时间</div>
                            <el-date-picker
                                v-model="createDate"
                                type="daterange"
                                :start-placeholder="'开始时间'"
                                :end-placeholder="'结束时间'"
                                range-separator="至"
                                :default-time="['00:00:00', '23:59:59']"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                format="yyyy-MM-dd HH:mm:ss"
                            ></el-date-picker>
                        </div>
                    </el-col>
                    <el-col :span="7" style="margin-left:2.8%">
                        <div class="depart-box">
                            <div class="slect-title" style="width: 150px;">最新跟进时间</div>
                            <el-date-picker
                                v-model="trackingDate"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :default-time="['00:00:00', '23:59:59']"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                format="yyyy-MM-dd HH:mm:ss"
                            ></el-date-picker>
                        </div>
                    </el-col>
                     <crm-perms-box perms="customer:student:importDepartment">
                        <el-col :span="4">
                            <div class="depart-box">
                                <div class="slect-title">导入部门</div>
                                <el-form-item>
                                    <el-select
                                        clearable
                                        v-model="queryBox.importDepartment"
                                        placeholder="请选择"
                                    >
                                        <el-option
                                            v-for="item in student_import_department"
                                            :key="item.key"
                                            :label="item.value"
                                            :value="item.key"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </div>
                        </el-col>
                    </crm-perms-box>
                </el-row>
                <el-row>
                   
                    <el-col :span="4">
                        <div class="depart-box">
                            <div class="slect-title">资源查询</div>
                            <el-select filterable clearable v-model="queryBox.dataFromGroupKey">
                                <el-option
                                    v-for="item in student_data_from_options"
                                    :key="item.key"
                                    :label="item.value"
                                    :value="item.key"
                                ></el-option>
                            </el-select>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <div class="depart-box">
                            <div class="slect-title">是否TMK</div>
                            <el-select filterable clearable v-model="queryBox.isTmkContacted">
                                <el-option
                                    v-for="item in tmk_option"
                                    :key="item.key"
                                    :label="item.value"
                                    :value="item.key"
                                ></el-option>
                            </el-select>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="code">
                            <el-input
                                type="number"
                                v-model="queryBox.trackingNum"
                                placeholder="跟进次数"
                            >
                                <template slot="prepend">跟进次数</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="keyWords">
                            <el-input v-model="queryBox.keyWords" placeholder="分主题">
                                <template slot="prepend">分主题</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                         <el-col :span="4">
                        <div class="depart-box">
                            <el-form-item label prop="isTodayTracking">
                                <div class="depart-box">
                                    <div class="slect-title">就读年级：</div>
                                    <el-select
                                        v-model="queryBox.grade"
                                        placeholder="请选择"
                                        :change="gradeChange"
                                    >
                                        <el-option
                                            v-for="item in gradeCache"
                                            :key="item.value"
                                            :label="item.fGradeName"
                                            :value="item.fId"
                                        ></el-option>
                                    </el-select>
                                </div>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
                <el-row class="area">
                    <el-col :span="6">
                        <div class="depart-box">
                            <div class="slect-title">客户来源</div>
                            <el-select
                                filterable
                                clearable
                                v-model="queryBox.dataFromGroupKeyF"
                                @change="dataFromGroupKeyChange"
                            >
                                <el-option
                                    v-for="item in resources_Options"
                                    :key="item.key"
                                    :label="item.value"
                                    :value="item.key"
                                ></el-option>
                            </el-select>
                            <el-select filterable clearable v-model="queryBox.dataFrom">
                                <el-option
                                    v-for="item in resourcesSon_Options"
                                    :key="item.id"
                                    :label="item.codeValue"
                                    :value="item.codeKey"
                                ></el-option>
                            </el-select>
                        </div>
                    </el-col>
                    <el-col :span="6">
                        <el-col :span="8" style="margin-left:0">
                            <span class="city-title">所在地区：</span>
                        </el-col>
                        <el-col :span="15" style="margin-left:-1px">
                            <el-form-item label prop="area">
                                <el-cascader
                                    clearable
                                    size="large"
                                    :options="options"
                                    v-model="selectedOptions"
                                ></el-cascader>
                            </el-form-item>
                        </el-col>
                    </el-col>
               
                    <el-col :span="5">
                        <el-form-item label prop="providerAgent">
                            <div class="depart-box">
                                <div class="slect-title">所属分中心</div>
                                <el-autocomplete
                                    v-model="branchCenterName"
                                    :fetch-suggestions="querySearchAsync"
                                    placeholder="请输入内容"
                                    @select="handleSelect"
                                    clearable
                                    :change="handleClearable()"
                                ></el-autocomplete>
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div class="from-btns">
                <kt-button
                    :label="$t('action.reset')"
                    perms="true"
                    type="primary"
                    @click="reset('queryBox')"
                />
                <kt-button
                    :label="$t('action.search')"
                    perms="true"
                    type="primary"
                    @click="search"
                />
            </div>
        </div>
        <div class="add-btns fl">
            <kt-button
                :label="$t('导出')"
                perms="customerSea:student:export"
                type="primary"
                @click="handleExport"
                style="float:left;"
            />
            <kt-button
                label="批量领取"
                :disabled="this.selections.length===0"
                perms="customer:student:BatchReceive"
                type="primary"
                @click="handleBatchReceive"
            />
            <!-- 批量分配按钮 -->
            <kt-button
                :label="$t('action.batchdistribution')"
                :disabled="this.selections.length===0"
                perms="customerSea:student:batchdistribution"
                type="primary"
                @click="handlebatchdistribution"
            />
        </div>
        <!--批量分配-->
        <div class="batchdistribution-pop">
            <el-dialog :visible.sync="batchdistribution" :close-on-click-modal="false" width="30%">
                <el-row>
                    <el-col :span="24">
                        <span class="batchdistribution-pop-tit">客户分配</span>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <span class="checked-person">已经选择{{selections.length}}位客户</span>
                    </el-col>
                </el-row>
                <el-form :inline="true" :model="addstuformData" class="demo-form-inline">
                    <el-row>
                        <el-col :span="24">
                            <el-row>
                                <el-col :span="6">
                                    <span class="tit">划分方式：</span>
                                </el-col>
                                <el-col :span="18">
                                    <el-select
                                        clearable
                                        v-model="deptmodeoptionsValue"
                                        placeholder="请选择"
                                        @change="deptmodeoptionsChange"
                                    >
                                        <el-option
                                            v-for="item in deptmodeoptions"
                                            :key="item.index"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                    <el-row style="margin-top:5%" v-if="isShowFlag==1||isShowFlag==2">
                        <el-col :span="24">
                            <el-row>
                                <el-col :span="6">
                                    <span class="tit">选择部门：</span>
                                </el-col>
                                <el-col :span="18">
                                    <popup-tree-input
                                        :data="deptData"
                                        :props="deptTree"
                                        :prop="deptinputValue"
                                        :currentChangeHandle="handleTreeSelectChange3Add"
                                    ></popup-tree-input>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                    <el-row style="margin-top:5%" v-if="isShowFlag==2">
                        <el-col :span="24">
                            <el-row>
                                <el-col :span="6">
                                    <span class="tit">人员选择：</span>
                                </el-col>
                                <el-col :span="18">
                                    <el-select
                                        clearable
                                        v-model="deptuseroptionValue"
                                        placeholder="请选择"
                                        @change="deptuserchange"
                                    >
                                        <el-option
                                            v-for="item in deptuseroption"
                                            :key="item.id"
                                            :label="item.realName"
                                            :value="item.id"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                </el-form>

                <span slot="footer" class="dialog-footer">
                    <el-button @click="batchdistribution = false">取 消</el-button>
                    <el-button
                        type="primary"
                        v-if="isShowFlag==1"
                        @click="batchdistributionsubmitdept"
                    >确 定</el-button>
                    <el-button
                        type="primary"
                        v-if="isShowFlag==2"
                        @click="batchdistributionsubmituser"
                    >确 定</el-button>
                </span>
            </el-dialog>
        </div>
        <!--表格内容栏-->
        <Crm-table
            class="table-width"
            studentCustomerSea
            @selectionChange="selectionChange"
            width="400"
            permsReceive="customerSea:student:Receive"
            :data="pageResult"
            :columns="columns"
            :loading="loading"
            @handleSee="handleSee"
            @handleReceive="handleReceive"
            @findPage="findPage"
        ></Crm-table>
    </div>
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import CrmTable from "@/views/Core/CrmTable";
import CrmSwitch from "@/views/Core/CrmSwitch";
import { CodeToText } from "element-china-area-data";
import { baseUrl } from "@/utils/global";
import axios from "axios";
import { regionDataPlus } from "element-china-area-data";
import Cookies from "js-cookie";
import CrmPermsBox from "@/views/Core/Crmpermsbox";
export default {
    name: "Student",
    components: {
        PopupTreeInput,
        CrmTable,
        KtButton,
        CrmSwitch,
        CrmPermsBox
    },
    data() {
        return {
            isShowFlag: 0, //0:初始化部门、人员不显示  1:部门显示 2：人员显示
            aa: true,
            checkedPeson: 0,
            size: "small",
            // filters: {
            //   name: ""
            // },
            // 查询条件
            student_data_from_options: [
                {
                    label: " ",
                    key: " "
                }
            ],
            grade_cache_gradeOptions: [],
            student_type_options: [],
            student_progress_options: [
                {
                    label: " ",
                    key: " "
                }
            ],
            student_data_from_type_options: [
                {
                    label: " ",
                    key: " "
                }
            ],
            student_import_department: [],
            queryBox: {
                name: "",
                dataFrom: "",
                type: "",
                dataFromType: "",
                progress: "",
                code: "",
                phone: "",
                school: "",
                providerTeacher: "",
                providerAgent: "",
                createDate: "",
                moveDate: "",
                belongToPerson: "",
                pageNum: 0,
                pageSize: 0,
                importDepartment: ""
            },
            width: 200,
            columns: [
                { type: "index", label: "序号", minWidth: 50 },
                { prop: "name", label: "学生姓名", minWidth: 80 },
                { prop: "school", label: "学校名称", minWidth: 100 },
                {
                    prop: "laiyuan",
                    label: "客户来源",
                    minWidth: 100
                    // id: "customerSource"
                },
                { prop: "getType", label: "获取方式", minWidth: 70 },
                { prop: "TMK", label: "是否TMK", minWidth: 80 },
                { prop: "getprogress", label: "客户进展", minWidth: 70 },
                { prop: "type", label: "客户类型", minWidth: 70 },
                { prop: "keyWords", label: "分主题", minWidth: 150 },
                { prop: "grade", label: "所在年级", minWidth: 120 },
                { prop: "parentName", label: "联系人", minWidth: 100 },
                { prop: "diqu", label: "地区", minWidth: 190 },
                { prop: "areaInput", label: "详细地址", minWidth: 120 },
                { prop: "createDate", label: "创建时间", minWidth: 140 },
                { prop: "trackingDate", label: "最新跟进时间", minWidth: 140 },
                { prop: "code", label: "客户编号", minWidth: 150 }
            ],
            pageRequest: { pageNum: 1, pageSize: 10 },
            pageResult: {
                content: []
            },
            student_type_options: [],
            operation: true, // true:新增, false:编辑
            batchdistribution: false, //显示批量分配弹窗
            customerownership: false, //显示客户归属弹窗
            selectionsLength: "",
            deptTreeProps: {
                label: "name",
                children: "children"
            },
            roles: [],
            selections: [], //选中列表集合
            ids: [], //分配ID集合
            ids2: [],
            deptData: [], //部门树
            deptTree: {
                label: "deptName",
                children: "children"
            },
            deptinputValue: "",
            // 划分方式
            deptmodeoptions: [
                {
                    label: "分配至部门",
                    value: "11"
                },
                {
                    label: "分配至个人",
                    value: "9"
                }
            ],
            deptmodeoptionsValue: "",
            submitID: "",
            deptId: "",
            userID: "", //人员ID
            deptuseroption: [], //部门用户
            deptuseroptionValue: "",
            branchcenter: [], //分中心下拉
            branchcenterValue: "",
            branchcenterValueID: "",
            branchcenterCodeValue: "", //分中心编码
            addstuformData: {},
            student_type_options: [],
            trackingDate: "",
            createDate: "",
            //   地区
            options: regionDataPlus,
            selectedOptions: [],
            loading: false,
            gradeCache: "",
            deptData: [], //部门树
            deptTree: {
                label: "deptName",
                children: "children"
            },
            deptinputValue: "",
            // 划分方式
            deptmodeoptions: [
                {
                    label: "分配至部门",
                    value: "11"
                },
                {
                    label: "分配至个人",
                    value: "9"
                }
            ],
            userName: "",
            branchCenterName: "",
            selections: [], //选中列表集合
            batchdistribution: false, //显示批量分配弹窗
            roleId: "", //当前登录用户的角色id
            // roleId1: "307922416041209975", //咨询师
            // roleId2: "307922480151146627", //直销三级部门管理
            // roleId3: "307922544034590863", //直销部门管理
            // roleId4: "318843899038940998", //金丰和校区管理
            // roleId5: "318845886098849661", //金丰和班主任管理
            roleId1: "", //咨询师
            roleId2: "", //直销三级部门管理
            roleId3: "", //直销部门管理
            roleId4: "", //金丰和校区管理
            roleId5: "", //金丰和班主任管理
            resources_Options: [],
            tmk_option: [
                {
                    key: "1",
                    value: "是"
                },
                {
                    key: "2",
                    value: "否"
                }
            ],
            resources_Options: [],
            student_data_from_options_son: [],
            resourcesSon_Options:[]
        };
    },
    methods: {
        // 搜索
        search() {
            this.loading = true;
            this.queryBox.createDateStart = this.createDate[0];
            this.queryBox.createDateEnd = this.createDate[1];
            this.queryBox.trackingDateStart = this.trackingDate[0];
            this.queryBox.trackingDateEnd = this.trackingDate[1];
            this.queryBox.province = this.selectedOptions[0];
            this.queryBox.city = this.selectedOptions[1];
            this.queryBox.area = this.selectedOptions[2];
            this.pageRequest.pageNum = 1;
            this.findPage(null);
        },
        // 获取分页数据
        findPage: function(data) {
            if (data !== null) {
                this.loading = true;
                this.pageRequest = data.pageRequest;
            }
            this.queryBox.pageSize = this.pageRequest.pageSize;
            this.queryBox.pageNum = this.pageRequest.pageNum;
            this.$api.student
                .studentQueryCustomerSea(this.queryBox)
                .then(res => {
                    let content = {
                        content: res.listStudentInfo,
                        totalSize: res.total
                    };
                    this.pageResult = content;
                    this.pageResult.content.forEach(item => {
                        if (item.province == null || item.province == "null") {
                            item.diqu = "";
                        } else if (
                            (item.province != null && item.city == null) ||
                            (item.province != "null" && item.city == "null")
                        ) {
                            item.diqu = CodeToText[item.province];
                        } else if (
                            (item.province != null &&
                                item.city != null &&
                                item.area == null) ||
                            (item.province != "null" &&
                                item.city != "null" &&
                                item.area == "null")
                        ) {
                            item.diqu =
                                CodeToText[item.province] +
                                CodeToText[item.city];
                        } else if (
                            (item.province != null &&
                                item.city != null &&
                                item.area != null) ||
                            (item.province != "null" &&
                                item.city != "null" &&
                                item.area != "null")
                        ) {
                            item.diqu =
                                CodeToText[item.province] +
                                CodeToText[item.city] +
                                CodeToText[item.area] +
                                (item.areaInput == null ? "" : item.areaInput);
                        }
                        if (item.isTmkContacted == 1) {
                            item.TMK = "是";
                        } else {
                            item.TMK = "否";
                        }
                        this.student_data_from_options2.forEach(type_item => {
                            if (type_item.key == item.dataFrom) {
                                item.laiyuan = type_item.value;
                            }
                        });
                        this.student_progress_options.forEach(progress_item => {
                            if (progress_item.key == item.progress) {
                                item.getprogress = progress_item.value;
                            }
                        });
                        // 获取方式对应
                        this.student_data_from_type_options.forEach(
                            data_from_type_item => {
                                if (
                                    data_from_type_item.key == item.dataFromType
                                ) {
                                    item.getType = data_from_type_item.value;
                                }
                            }
                        );
                        // 客户类型对应
                        this.student_type_options.forEach(student_type_item => {
                            if (student_type_item.key == item.type) {
                                item.type = student_type_item.value;
                            }
                        });
                        //年级
                        this.gradeCache.forEach(gradeItem => {
                            if (gradeItem.fId == item.grade) {
                                item.grade = gradeItem.fGradeName;
                            }
                        });
                    });
                    this.loading = false;
                })
                .then(data != null ? data.callback : "");
        },
        // 重置
        reset(queryBox) {
            this.$refs.queryBox.resetFields();
            this.queryBox.type = "";
            this.queryBox.dataFrom = "";
            this.queryBox.progress = "";
            this.queryBox.providerAgent = "";
            this.createDate = "";
            this.trackingDate = "";
            this.queryBox.dataFromType = "";
            this.queryBox.createDateStart = "";
            this.queryBox.createDateEnd = "";
            this.queryBox.trackingDateStart = "";
            this.queryBox.trackingDateEnd = "";
            this.selectedOptions = [];
            this.queryBox.province = "";
            this.queryBox.city = "";
            this.queryBox.area = "";
            this.pageRequest.pageNum = 1;
            this.queryBox.phone = "";
            this.queryBox.grade = "";
            this.userName = "";
            this.branchCenterName = "";
            this.queryBox.dataFromGroupKey = "";
            this.queryBox.importDepartment = "";
            this.queryBox.isTmkContacted = "";
            this.queryBox.trackingNum = "";
            this.queryBox.keyWords = "";
            this.queryBox.dataFromGroupKey = "";
            this.queryBox.dataFromGroupKeyF = "";
            this.loading = true;
            this.findPage(null);
        },
        // 领取
        handleReceive(params) {
            this.$api.student
                .studentAssignResourceAssign({
                    listStudentId: params.row.id.split(),
                    belongType: 9,
                    fromHqSea:1,
                    belongTo: Cookies.get("userId")
                })
                .then(res => {
                    if (res.result == 2) {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "success"
                        });
                        this.findPage(null);
                    }
                });
        },
        // 批量领取
        handleBatchReceive() {
            let idstu = this.selections.map(item => item.id);
            this.$confirm(
                `确认领取${this.selections.length}个客户吗？`,
                "提示",
                {}
            ).then(() => {
                // this.editLoading = true;
                this.$api.student
                    .studentAssignResourceAssign({
                        listStudentId: idstu,
                        belongType: 9,
                        fromHqSea:1,
                        belongTo: Cookies.get("userId")
                    })
                    .then(res => {
                        if (res.result == 2) {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "success"
                            });
                            this.findPage(null);
                        }
                    });
            });
        },
        // 获取来源
        get_student_data_from() {
            this.student_data_from_options2 = JSON.parse(
                localStorage.getItem("studentSource")
            );
        },
        get_student_progress() {
            this.student_progress_options = JSON.parse(
                localStorage.getItem("studenProgress")
            );
        },
        student_progress_change(value) {
            this.queryBox.student_progressValue = value.toString();
        },
        get_student_type() {
            this.student_type_options = JSON.parse(
                localStorage.getItem("stdentTpye")
            );
        },
        get_student_data_from_type() {
            this.student_data_from_type_options = JSON.parse(
                localStorage.getItem("stdentDataFromType")
            );
        },
        student_parent_type_change(value) {
            this.info.studentInfoDetail.studentInfoAttr.parentType = value.toString();
        },
        // 获取年级
        get_grade() {
            this.gradeCache = JSON.parse(localStorage.getItem("gradeCache"));
        },
        gradeChange(item) {
            this.queryBox.grade = item.fId;
        },
        // 查看客户档案
        handleSee: function(params) {
            this.dataForm = Object.assign({}, params.row);
            // 
            this.$router.push({
                path: "/Customerfile/Student",
                query: {
                    id: this.dataForm.id
                }
            });
        },

        // 导出
        handleExport() {
            axios({
                method: "get",
                url: baseUrl + "/studentInfo/exportCustomerSea",
                params: this.queryBox
            }).then(res => {
                window.open(res.request.responseURL);
            });
        },

        // 分中心远程搜索
        querySearchAsync(queryString, callback) {
            let restaurants = [{}];
            let results = "";
            this.$api.dropdown.branchcenter().then(res => {
                
                for (let i of res.branchCenterInfoList) {
                    i.value = i.name; //将想要展示的数据作为value
                }
                restaurants = res.branchCenterInfoList;
                results = queryString
                    ? restaurants.filter(this.createFilter(queryString))
                    : restaurants;
                callback(results);
            });
        },
        createFilter(queryString) {
            return restaurant => {
                return (
                    restaurant.name
                        .toLowerCase()
                        .indexOf(queryString.toLowerCase()) === 0
                );
            };
        },

        handleClearable(value) {
            if (this.userName == "") {
                this.queryBox.belongTo = "";
            }
            if (this.userDerpatName == "") {
                this.queryBox.departmentId = "";
            }
            if (this.branchCenterName == "") {
                this.queryBox.providerAgent = "";
            }
        },
        // 搜索所属分中心
        handleSelect(item) {
            this.queryBox.providerAgent = item.id;
        },
        // 获取导入部门
        get_student_importDepartment() {
            this.$api.user
                .optionsList({ codeType: "student_import_department" })
                .then(res => {
                    this.student_import_department = res.keyValueList;
                });
        },
        // 获取选中的表格数据
        selectionChange: function(selections) {
            this.selections = selections.selections;
        },
        // 批量分配
        handlebatchdistribution(params) {
            this.batchdistribution = true;
            this.ids = [];
            let idstu = this.selections.map(item => item.id);
            // this.dataFormAdd = Object.assign({}, params.row);
            this.ids = idstu;
            this.deptmodeoptionsValue = "";
            this.deptinputValue = "";
            this.deptuseroptionValue = "";
            this.isShowFlag = 0;
        },
        // 批量分配提交
        batchdistributionsubmitdept() {
            this.$api.user
                .studentAssign_customerManager({
                    listStudentId: this.ids,
                    belongType: this.deptmodeoptionsValue,
                    belongTo: this.deptId,
                    assignType: 3
                })
                .then(res => {
                    if (res.result === 1) {
                        this.$message({
                            message: res.msg,
                            type: "success"
                        });
                        this.batchdistribution = false;
                        this.findPage(null);
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                });
        },
        batchdistributionsubmituser() {
            this.$api.user
                .studentAssign_customerManager({
                    listStudentId: this.ids,
                    belongType: this.deptmodeoptionsValue,
                    belongTo: this.userID,
                    assignType: 3
                })
                .then(res => {
                    if (res.result === 1) {
                        this.$message({
                            message: res.msg,
                            type: "success"
                        });
                        this.batchdistribution = false;
                        this.findPage(null);
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                });
        },
        //划分方式 控制部门人员显示
        deptmodeoptionsChange(value) {
            if (value == 9) {
                this.isShowFlag = 2;
            } else if (value == 11) {
                this.isShowFlag = 1;
            } else {
                this.isShowFlag = 0;
            }
        },
        // 点击部门
        handleTreeSelectChange3Add(data, node) {
            this.deptinputValue = data.deptName;
            this.deptuseroptionValue = "";
            this.deptId = data.id;
            this.get_dept_user();
        },
        // 获取部门数据
        get_dept_data() {
            this.$api.dropdown.deptLevel3({ deptType: 1 }).then(res => {
                this.tableData = res.departmentInfoList;
                this.deptData = res.departmentInfoList;
                this.date = res.departmentInfoList;
                this.date.forEach(item => {
                    item.text = item.deptName;
                    item.value = item.deptName;
                });
            });
        },
        // 获取部门用户
        get_dept_user() {
            this.$api.dropdown
                .users({
                    userType: 3,
                    threeLevelDeptId: this.deptId,
                    accountStatus: 1,
                    isControlResource: 1
                })
                .then(res => {
                    this.deptuseroption = res.userInfoList;
                });
        },
        deptuserchange(value) {
            this.userID = value;
        },
        // 查询角色信息
        queryUserRole() {
            this.$api.role.queryUserRole().then(res => {
                if (res.result == 1) {
                    this.roleId = res.userInfo.roleId;
                    if (
                        this.roleId == this.roleId1 ||
                        this.roleId == this.roleId2 ||
                        this.roleId == this.roleId3 ||
                        this.roleId == this.roleId4 ||
                        this.roleId == this.roleId5
                    ) {
                        this.columns.map(item => {
                            if (item.id) {
                                item.customerSource = "customerSource";
                            }
                        });
                    }
                }
            });
        },
        // 资源查询
        // studentDataFromGroup() {
        //     this.$api.dropdown.studentDataFromGroup().then(res => {
        //         if (res.result == 1) {
        //             this.resources_Options = res.keyValueList;
        //         }
        //     });
        // },
        // 资源查询二级
        dataFromGroupKeyChange(params) {
            this.queryBox.dataFrom=''
            if (params != "") {
                this.$api.dropdown
                    .queryStudentDataFromByGroupId({
                        id: params
                    })
                    .then(res => {
                        if (res.result == 2) {
                            this.$message({ message: res.msg, type: "error" });
                        } else {
                            this.resourcesSon_Options = res.data;
                        }
                    });
            }
        },
        //资源查询
        studentDataFromGroup2() {
            this.$api.dropdown.studentDataFromGroup().then(res => {
                if (res.result == 1) {
                    for (var i = 0; i < res.keyValueList.length; i++) {
                        if (res.keyValueList[i].value == "其他") {
                            res.keyValueList.splice(i, 1);
                        }
                    }
                    this.student_data_from_options = res.keyValueList;
                }
            });
        },
    },
     beforeMount: function() {
        this.$api.dropdown.studentDataFromGroup().then(res => {
            if (res.result == 1) {
                this.resources_Options = res.keyValueList;
            }
        });
        this.studentDataFromGroup2();
    },
    mounted() {
        this.get_student_data_from();
        this.get_student_progress();
        this.get_student_type();
        this.get_student_data_from_type();
        this.get_grade();
        this.get_dept_data();
        this.get_student_importDepartment();
        this.queryUserRole();
        // this.studentDataFromGroup();
    }
};
</script>
<style >
@import url("../../assets/queryBox.css");
</style>
<style lang='scss' scoped>
.checked-person {
    display: block;
    float: left;
    margin-top: -10%;
    margin-left: 35%;
}
.batchdistribution-pop-tit {
    font-size: 20px;
    font-weight: bold;
    display: inline-block;
    color: #303133;
}
.checked-person {
    font-weight: 500;
    display: inline-block;
    text-align: center;
    margin: 3% 0 3% 40%;
}
.batchdistribution-pop-tit {
    font-size: 20px;
    font-weight: bold;
    display: inline-block;
    color: #303133;
}
.demo-form-inline {
    width: 90%;
    margin: 0 auto;
    .el-dialog__body .el-input {
        width: 93% !important;
    }
    .el-select {
        width: 100% !important;
    }
    .tit {
        display: inline-block;
        margin-top: 10%;
    }
}
.el-dialog__wrapper .el-form-item__content {
    margin-left: 0;
}
</style>
<style lang='scss'>
.batchdistribution-pop {
    .el-dialog__header {
        text-align: left;
        margin-left: 10%;
        font-weight: bold;
    }
}
.batchdistribution-pop .el-dialog__header {
    padding: 0 0 0 0 !important;
}
.batchdistribution-pop .el-autocomplete {
    width: 100% !important;
}
</style>


